<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>疫苗批次号信息管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/change/change.js"></script>
<script src="${ctxStatic}/common/check/check.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		//$("#name").focus();
		$("#inputForm").validate({
			submitHandler: function(form){
				postOrderDetil(form);
				/* loading('正在提交，请稍等...');
				form.submit(); */
			}
		});
		
		initVaccNameInfo(bsVaccineBatchno.companyCode,bsVaccineBatchno.vaccineId);
		$("#vaccineId").change(function(){
			initCompanyNameInfo($(this).val());
			$("#vid").val("");
			$("#spec").val("");//规格
			$("#doseType").val("");//剂型
			$("#largePackage").val("");//大包装
			$("#dose").val("");					//剂量
			$("#containerType").val("");//容器类型
			$("#customBillNo").val("");//批准文号
			$("#vaccNameAll").val(""); //疫苗全称
			$("#vaccineName").val("");//疫苗简称 
			$("#type").val("");//
		});
		$("#companyCode").change(function(){
			var vaccineId = $("#vaccineId").val();
			var companyCode = $(this).val();
			if (vaccineId!=''&&companyCode!=''){
				open(vaccineId,companyCode);
			}
		});
		
		$("#code").blur(function(){
			var code = $(this).val();
			if(code != ''){
			     $("#s2id_entrance a span:first").text("是");
			     $("#entrance").val("1");
			}
		});
		
		$("#batchno").blur(function(){
			if (checkBatchno()){
				check();
			}
		});
		
		$("#batchno1").blur(function(){
			check();
		});
		
		$("#secondBatchno").blur(function(){
			if (checkBatchno()){
				check();
			}
		});
		
		setTimeout(function () {
			layer.open({
				anim: 2,
				title:'批号维护须知',
				btn: '知道了',
				shade: 0,
				offset: 'rb', //右下角弹出
				type: 2,
				maxmin: true,
				area: ['600px', '400px'],
				content: '${ctx}/vaccinate/bsVaccineBatchno/notice'
			});
		}, 1000);
	});
	
	var bsVaccineBatchno = JSON.parse('${fns:toJson(bsVaccineBatchno)}');
	
	function open(vaccineId,companyCode){
		$("div[data-line=line1]").find("span[data=add]").text("正在查询中...");
		var height = window.screen.height - 600;
		var width = window.screen.width -800;
		var  url = "${ctx}/vaccinate/bsVaccineInfo/getList?vaccineId="+vaccineId+"&companyCode="+companyCode;
		    layer.open({
	        type: 2,
	        title: '',
	        shadeClose: true,
	        skin: 'layui-layer-rim',
	        shade: 0.8,
	        closeBtn:true,
	        resize:false,
	        area: [width+"px", height+"px"],
	        content: url
      	});
	}
	
	function addInfo(info){
		$("#vid").val(info.id);
		$("#spec").val(info.spec);//规格
		$("#doseType").val(info.doseType1);//剂型
		$("#largePackage").val(info.largePackage);//大包装
		$("#dose").val(info.dose);					//剂量
		$("#containerType").val(info.containerTypeNam1);//容器类型
		$("#customBillNo").val(info.customBillNo);//批准文号
		$("#vaccNameAll").val(info.vaccNameAll); //疫苗全称
		$("#businessName").val(info.vaccName);//业务名称 
		$("#vaccineName").val(info.vaccName);
		$("#type").val(info.type);//
		$("div[data-line=line1]").find("span[data=add]").text("已查询");
		if(info.spec == ''){
			$("#spec").attr("readonly",false);
		}
	}
	
	function checkBatchno(){
		var bacthno = $("#batchno").val();
		var secondBatchno = $("#secondBatchno").val();
		/* var number = bacthno.indexOf("-");
		if(number > 0 && secondBatchno == ''){
			secondBatchno = bacthno.substring(number+1);
			bacthno = bacthno.substring(0,number);
		} */
		if($("#batchno").val()==""){
			$("#batchno").nextAll('label[data-batcho=update]').text("请输入批号!").show();
			return false;
		}else{
			var flag =false;
			var url = "${ctx}/vaccinate/bsVaccineBatchno/checkBatchno";
			$.ajax({
				url :url,
				async: false,
				data :{"batchno":bacthno,
					 "vaccineId":$("#vaccineId").val(),
                     "companyCode":$("#companyCode").val(),
                     "secondBatchno":secondBatchno/*  */
                     } ,
				success : function(data){
					if(data.length>0){
						$("#batchno").nextAll('label[data-batcho=update]').text("该批次已存在!").show();
					}else{
						$("#batchno").nextAll('label[data-batcho=update]').text("").hide();
						flag = true;
					}
				}
			});
			return flag;
		}
	}
	
	function check(){
		var batchno1 =$("#batchno1").val();
		var batchno =$("#batchno").val();
		if($("#batchno").val()==""){
			$("#batchno").nextAll('label[data-batcho=update]').text("请输入批次号!").show();
			//$("#ll").text("请输入批号!");
			return false;
		}
		if(batchno1 != batchno){
			$("#batchno1").nextAll('label[data-batcho=update]').text("批次号不一致，请重新输入!").show();
			return false;
		}else{
			$("#batchno1").nextAll('label[data-batcho=update]').text("").hide();
			return true;
		}
	}

	function closeIframe(){
		var index = parent.layer.getFrameIndex(window.name);
		if(index){
			parent.layer.close(index);
		}else{
			window.location.href = "${ctx}/vaccinate/bsVaccineBatchno/manageBatchno?batchType=1";
		}
	}
	
	function rese(){			
		location.reload();
	}

	function postOrderDetil(form) {//表单保存时  将此方法中的数据尽行保存
		if(!$("#vid").valid() || $("#vid").val()==""){
			$("div[data-line=line1]").find("span[data=add]").text("未关联！");
			layer.msg('未关联疫苗信息！');
			return;
		}
		if(!checkBatchno()){
			layer.msg('批号重复，请检查录入数据是否有误！');
			return;
		}
		if (!check()) {
			layer.msg('确认批号不正确，请检查录入数据是否有误！');
			return;
		}
		/* var vaccineNameText = $("#vaccineId").find("option:selected").text();
		var vaccineName = vaccineNameText.substring(0,vaccineNameText.indexOf('[')); */
		var companyName = $("#companyCode").find("option:selected").text();
		/* $("#vaccineName").val(vaccineName); */
		$("#businessName").val($("#vaccineName").val());
		$("#companyName").val(companyName);
		layer.confirm('确定保存？', {
			btn : [ '保存', '取消' ]
		//按钮
		}, function() {
			layer.load(2);
			loading('正在提交，请稍等...');
			form.submit();
		});
	}
</script>
<style type="text/css">
    /*修改提示文字的颜色分不同的浏览器*/
	#batchno::-webkit-input-placeholder { /* WebKit browsers */ 
	   color: #db136075; 
	} 
	#batchno:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ 
	   color: #db136075; 
	} 
	#batchno::-moz-placeholder { /* Mozilla Firefox 19+ */
	   color: #db136075; 
	} 
	#batchno:-ms-input-placeholder { /* Internet Explorer 10+ */ 
	   color: #db136075; 
	} 
	
	#secondBatchno::-webkit-input-placeholder { /* WebKit browsers */ 
	   color: #db136075; 
	} 
	#secondBatchno:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ 
	   color: #db136075; 
	} 
	#secondBatchno::-moz-placeholder { /* Mozilla Firefox 19+ */
	   color: #db136075; 
	} 
	#secondBatchno:-ms-input-placeholder { /* Internet Explorer 10+ */ 
	   color: #db136075; 
	} 
	
	#code::-webkit-input-placeholder { /* WebKit browsers */ 
	   color: #db136075; 
	} 
	#code:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ 
	   color: #db136075; 
	} 
	#code::-moz-placeholder { /* Mozilla Firefox 19+ */ 
	   color: #db136075; 
	} 
	#code:-ms-input-placeholder { /* Internet Explorer 10+ */ 
	   color: #db136075; 
	}
	
	#largePackage::-webkit-input-placeholder { /* WebKit browsers */ 
	   color: #db136075; 
	} 
	#largePackage:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ 
	   color: #db136075; 
	} 
	#largePackage::-moz-placeholder { /* Mozilla Firefox 19+ */ 
	   color: #db136075; 
	} 
	#largePackage:-ms-input-placeholder { /* Internet Explorer 10+ */ 
	   color: #db136075; 
	}
	
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active">
			<a>增加疫苗批次号</a>
		</li>
	</ul>
	<br/>
	<form:form id="inputForm" modelAttribute="bsVaccineBatchno" action="${ctx}/vaccinate/bsVaccineBatchno/save" 
		method="post" class="form-horizontal"  enctype="multipart/form-data">
	<form:input type="hidden" id="vid" path="vid"/>
	<form:input type="hidden" path="type" id="type" />
	<form:input type="hidden" path="batchType" id="batchType" />
	<form:input type="hidden" id="createOrgCode" path="createOrgCode"/>
	<form:input type="hidden" id="createOrgName" path="createOrgName"/>
	<form:input type="hidden" id="businessName" path="businessName"/>
	<form:input type="hidden" id="companyName" path="companyName"/>
	<sys:message content="${message}"/>
	<div class="container-fluid">

	<div class="row-fluid">
		<div class="control-group span6 minWidth" data-line="line1">
			<label class="control-label"><font color="red">*</font> 疫苗名称：</label>
			<div class="controls">
			<select id="vaccineId" name="vaccineId" class="span7 vaccineCompany required"> </select>
			</div>
		</div>
		
		<div class="control-group span6 minWidth" data-line="line2">
			<label class="control-label"><font color="red">*</font> 生产企业：</label>
			<div class="controls">
			<select id="companyCode" name="companyCode" class="span7 selectCompany required"> </select>
			</div>
		</div>
	</div>	
    <div class="row-fluid">
        <div class="control-group span6 minWidth">
			<label class="control-label">疫苗简称：</label>
			<div class="controls">
				<input type="text" id="vaccineName" name="vaccineName" class="span7 required" value="${bsVaccineBatchno.vaccineName}" readonly="readonly"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">疫苗全称：</label>
			<div class="controls">
				<input type="text" id="vaccNameAll" name="vaccNameAll" class="span7 required" value="${bsVaccineBatchno.vaccNameAll}" readonly="readonly"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">规格：</label>
			<div class="controls">
				<form:input type="text" id="spec" path="spec" readonly="true"  maxlength="32" class="span7 required digits"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">批准文号：</label>
			<div class="controls">
				<input type="text"  id="customBillNo" name="customBillNo" maxlength="32" class="span7"/>
			</div>
		</div>
	</div>
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 批号：</label>
			<div class="controls">
				<input type="text" id="batchno" name="batchno"   maxlength="32" class="span7  required"  placeholder="批号与批签发上面批号一致(注意大小写的区分)"/>
				<label hidden="true" class="error" data-batcho="update"></label>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 确认批号：</label>
			<div class="controls">
				<input type="text" id="batchno1" name="batchno1"  maxlength="32" class="span7 required" />
				<label hidden="true" class="error" data-batcho="update"></label>
			</div>
		</div>
	</div>

	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">亚批号：</label>
			<div class="controls">
				<input type="text" id="secondBatchno" name="secondBatchno"   maxlength="32" class="span7 " placeholder="亚批号填写规则，例如  1  或  2等数字格式"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 有效日期至：</label>
			<div class="controls">
				<input id="outBoundDate" name="outBoundDate" type="text" maxlength="20" class=" Wdate required"
					value="" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</div>
		</div>
	</div>	
	
	<div class="row-fluid">	
	   <div class="control-group span6 minWidth">
			<label class="control-label">剂型：</label>
			<div class="controls">
				<input type="text" id="doseType" name="doseType"  readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">剂量：</label>
			<div class="controls">
				<input type="text" id="dose" name="dose" readonly="readonly"  maxlength="32" class="span7"/>
			</div>
		</div>
	</div>
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">* </font>大包装(支(粒)/箱)：</label>
			<div class="controls">
				<input type="text" id="largePackage" name="largePackage" maxlength="32" class="span7 digits required" placeholder="每箱多少支或粒，例：500(输入整数)"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">* </font>最小分包装(支(粒)/盒):</label>
			<div class="controls">
				<input type="text" id="smallPackage" name="smallPackage" maxlength="32" class="span7 digits required"/>
			</div>
		</div>
	</div>
	
	<div class="row-fluid">	
		<div class="control-group span6 minWidth">
			<label class="control-label">接种途径：</label>
			<div class="controls">
				<select id="inoculation" name="inoculation" class="span7">
					<option value="">-请选择-</option>
					<c:forEach items="${fns:getDictList('inoculation_route')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">是否为进口疫苗：</label>
			<div class="controls">
				<select id="entrance" name="entrance" class="span7">
					<option value="">-请选择-</option>
					<option value="1">是</option>
					<option value="0">否</option>
				</select>
		</div>
		</div>
	</div>	
	<div class="row-fluid">	
	    <div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">* </font>批签发合格证明编号：</label>
			<div class="controls">
				<input type="text"  id="certifiCode" name="certifiCode" maxlength="32" class="span7 required"/>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">* </font>进口通关单编号：</label>
			<div class="controls">
				<input type="text"  id="code" name="code" maxlength="32" class="span7" placeholder="进口疫苗需填写通关单号,如不是进口疫苗可不填写"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">	
	    <div class="control-group span6 minWidth">
			<label class="control-label">批签发合格证明文件：</label>
			<div class="controls">
				<input type="file"  id="pdfFile" name="pdfFile" class="input-mini" onchange="checkFile(this);"/>
				<span style="color:#db1360; font-size:12px;font-style:italic;">*可上传的类型有PDF,JPG,PNG,JPEG</span>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">容器类型：</label>
			<div class="controls">
				<input type="text" id="containerType" name="containerType" readonly="readonly"  maxlength="255" class="span7"/>
			</div>
		</div>
	</div>	
	
	<div class="form-actions">
		<button id="btnSubmit" class="btn btn-primary" type="submit" >保存</button>
		<button id="btnReset" class="btn" type="button" onclick = "rese()">重置</button>
		<!-- <button id="btnCancel" class="btn" type="button" onclick="history.go(-1)">返回</button> -->
		<button id="btnClose" class="btn" type="button" onclick="closeIframe()">关闭</button>
	</div>
	</div>
	</form:form>
</body>
</html>